]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Port to MetaContext
authorJonas Ådahl <jadahl@gmail.com>
Thu, 6 May 2021 21:17:40 +0000 (23:17 +0200)
committerMarge Bot <marge-bot@gnome.org>
Thu, 15 Jul 2021 12:42:17 +0000 (12:42 +0000)
This ports over gnome-shell and the theme test case to MetaContext,
instead of the various functions that were available before.

The test case is changed to use the special test context, used to
construct contexts for testing. It's part of a shared libary separate
from the main libmutter one.

This enables building mutter tests during CI, as the test framework is
needed by some of gnome-shell's tests.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1840>

.gitlab-ci.yml
meson.build
src/main.c
src/st/meson.build
src/st/test-theme.c

index 2f09743335d3e2e7156de7095d912cac9d6a531a..963b7885d2dcf514a4470c21c30bd30a35d09a41 100644 (file)
@@ -180,7 +180,7 @@ build:
     needs: ["check_commit_log"]
     before_script:
         - .gitlab-ci/checkout-mutter.sh
-        - meson mutter mutter/build --prefix=/usr -Dtests=false
+        - meson mutter mutter/build --prefix=/usr
         - ninja -C mutter/build install
     script:
         - meson . build -Dbuildtype=debugoptimized -Dman=false --werror
index f0a2b4c5521f58f61a8643a472eea791910e3350..a68a4065bacd1bfbc1f3ba7fa35504a65505b869 100644 (file)
@@ -17,6 +17,7 @@ clutter_pc = 'mutter-clutter-' + mutter_api_version
 cogl_pc = 'mutter-cogl-' + mutter_api_version
 cogl_pango_pc = 'mutter-cogl-pango-' + mutter_api_version
 libmutter_pc = 'libmutter-' + mutter_api_version
+libmutter_test_pc = 'libmutter-test-' + mutter_api_version
 
 ecal_req = '>= 3.33.1'
 eds_req = '>= 3.33.1'
@@ -87,6 +88,7 @@ clutter_dep = dependency(clutter_pc, version: mutter_req)
 cogl_dep = dependency(cogl_pc, version: mutter_req)
 cogl_pango_dep = dependency(cogl_pango_pc, version: mutter_req)
 mutter_dep = dependency(libmutter_pc, version: mutter_req)
+mutter_test_dep = dependency(libmutter_test_pc, version: mutter_req)
 polkit_dep = dependency('polkit-agent-1', version: polkit_req)
 startup_dep = dependency('libstartup-notification-1.0', version: startup_req)
 ibus_dep = dependency('ibus-1.0', version: ibus_req)
index a47154db177a41a774d780501e51a93fda9950f0..1eb0b1a2980e73f286a4d0899f1f2d1cbc7fbf49 100644 (file)
@@ -13,7 +13,7 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 #include <girepository.h>
-#include <meta/main.h>
+#include <meta/meta-context.h>
 #include <meta/meta-plugin.h>
 #include <meta/prefs.h>
 #include <atk-bridge.h>
@@ -442,33 +442,35 @@ GOptionEntry gnome_shell_options[] = {
 int
 main (int argc, char **argv)
 {
-  GOptionContext *ctx;
+  g_autoptr (MetaContext) context = NULL;
   GError *error = NULL;
-  int ecode;
+  int ecode = EXIT_SUCCESS;
 
   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
 
+  context = meta_create_context (WM_NAME);
+  meta_context_add_option_entries (context, gnome_shell_options,
+                                   GETTEXT_PACKAGE);
+  meta_context_add_option_group (context, g_irepository_get_option_group ());
+
   session_mode = (char *) g_getenv ("GNOME_SHELL_SESSION_MODE");
 
-  ctx = meta_get_option_context ();
-  g_option_context_add_main_entries (ctx, gnome_shell_options, GETTEXT_PACKAGE);
-  g_option_context_add_group (ctx, g_irepository_get_option_group ());
-  if (!g_option_context_parse (ctx, &argc, &argv, &error))
+  if (!meta_context_configure (context, &argc, &argv, &error))
     {
-      g_printerr ("%s: %s\n", argv[0], error->message);
-      exit (1);
+      g_printerr ("Failed to configure: %s", error->message);
+      return EXIT_FAILURE;
     }
 
-  g_option_context_free (ctx);
-
-  meta_plugin_manager_set_plugin_type (gnome_shell_plugin_get_type ());
-
-  meta_set_wm_name (WM_NAME);
-  meta_set_gnome_wm_keybindings (GNOME_WM_KEYBINDINGS);
+  meta_context_set_plugin_gtype (context, gnome_shell_plugin_get_type ());
+  meta_context_set_gnome_wm_keybindings (context, GNOME_WM_KEYBINDINGS);
 
-  meta_init ();
+  if (!meta_context_setup (context, &error))
+    {
+      g_printerr ("Failed to setup: %s", error->message);
+      return EXIT_FAILURE;
+    }
 
   /* FIXME: Add gjs API to set this stuff and don't depend on the
    * environment.  These propagate to child processes.
@@ -478,7 +480,7 @@ main (int argc, char **argv)
 
   shell_init_debug (g_getenv ("SHELL_DEBUG"));
 
-  shell_dbus_init (meta_get_replace_current_wm ());
+  shell_dbus_init (meta_context_is_replacing (context));
   shell_a11y_init ();
   shell_perf_log_init ();
   shell_introspection_init ();
@@ -504,7 +506,21 @@ main (int argc, char **argv)
     }
 
   shell_profiler_init ();
-  ecode = meta_run ();
+
+  if (!meta_context_start (context, &error))
+    {
+      g_printerr ("GNOME Shell failed to start: %s", error->message);
+      return EXIT_FAILURE;
+    }
+
+  if (!meta_context_run_main_loop (context, &error))
+    {
+      g_printerr ("GNOME Shell terminated with an error: %s", error->message);
+      ecode = EXIT_FAILURE;
+    }
+
+  meta_context_destroy (g_steal_pointer (&context));
+
   shell_profiler_shutdown ();
 
   g_debug ("Doing final cleanup");
index a74581ff8a58ad9f09bf012a3be886507d1163c3..8e4acdaaafc26e82e4594694b9f041330e36eea6 100644 (file)
@@ -194,7 +194,7 @@ libst_dep = declare_dependency(link_with: libst,
 test_theme = executable('test-theme',
   sources: 'test-theme.c',
   c_args: st_cflags,
-  dependencies: [mutter_dep, gtk_dep, libxml_dep],
+  dependencies: [mutter_test_dep, gtk_dep, libxml_dep],
   build_rpath: mutter_typelibdir,
   link_with: libst
 )
index cbc79f6b50c088ea868faeef7c4dc10ff473bde7..3fcbd99bb7eb0a83ef7be8c2559a5b05fa0025a4 100644 (file)
@@ -25,7 +25,7 @@
 #include "st-button.h"
 #include <math.h>
 #include <string.h>
-#include <meta/main.h>
+#include <meta-test/meta-context-test.h>
 #include <meta/meta-backend.h>
 
 static ClutterActor *stage;
@@ -538,6 +538,8 @@ test_inline_style (void)
 int
 main (int argc, char **argv)
 {
+  MetaContext *context;
+  g_autoptr (GError) error = NULL;
   MetaBackend *backend;
   StTheme *theme;
   StThemeContext *theme_context;
@@ -550,7 +552,13 @@ main (int argc, char **argv)
   /* meta_init() cds to $HOME */
   cwd = g_get_current_dir ();
 
-  meta_test_init ();
+  context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED,
+                                      META_CONTEXT_TEST_FLAG_NONE);
+  if (!meta_context_configure (context, &argc, &argv, &error))
+    g_error ("Failed to configure: %s", error->message);
+
+  if (!meta_context_setup (context, &error))
+    g_error ("Failed to setup: %s", error->message);
 
   if (chdir (cwd) < 0)
     g_error ("chdir('%s') failed: %s", cwd, g_strerror (errno));
@@ -623,7 +631,7 @@ main (int argc, char **argv)
   g_object_unref (text4);
   g_object_unref (theme);
 
-  clutter_actor_destroy (stage);
+  g_object_unref (context);
 
   return fail ? 1 : 0;
 }